package UIComponents.FriendGive
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	public class FriendGive extends Sprite
	{
		public  var filtersMzlb2:Array;			//迷之礼包2
		public  var filtersMzlbAsk2:Array;			//迷之礼包2问号
		public  var filtersMzlbAsk1:Array;			//迷之礼包1问号
		public 	 var filterslblock:Array;			//变灰
		public 	 var filtersHotTxt:Array;			//热感文本
		
		static public var instance:FriendGive;
		
		public var items:Array;
		
		public var selectItem:GiveItem=null;
		
		public var typeNumA:uint=0;
		public var typeNumB:uint=0;
		public var typeNumC:uint=0;
		
		public var maxNum:uint		=	3;
		public var typeAry:Array	=	[20,1,1];
		
		public function FriendGive()
		{
			instance 	=	this;
			items	= new Array;
			getFilters();
			
			init();
		}
		public function init():void
		{
			/*jstx_fuwuyuan_sl
			jstx_xiaochoujs_sl
			jstx_waixingrenjs_sl
			tufu_sl
			qunjishou_sl
			nvwujs_sl
			jixiegong_sl
			jiugui_sl
			hushijiangshi_sl
			fuwuyuan_sl*/
			this.addItem( {itemName:"服务员僵尸礼包",lock:false,isask:false,picName:"jstx_fuwuyuan_sl",type:"a"});
			this.addItem( {itemName:"小丑僵尸礼包",lock:false,isask:false,picName:"jstx_xiaochoujs_sl",type:"a"});
			this.addItem( {itemName:"外星人僵尸礼包",lock:false,isask:false,picName:"jstx_waixingrenjs_sl",type:"a"});
			this.addItem( {itemName:"屠夫僵尸礼包",lock:false,isask:false,picName:"jstx_tufu_sl",type:"b"});
			this.addItem( {itemName:"拳击手僵尸礼包",lock:false,isask:false,picName:"jstx_qunjishou_sl",type:"b"});
			this.addItem( {itemName:"女巫僵尸礼包",lock:false,isask:false,picName:"jstx_nvwujs_sl",type:"b"});
			this.addItem( {itemName:"机械师僵尸礼包",lock:false,isask:false,picName:"jstx_jixiegong_sl",type:"c"});
			this.addItem( {itemName:"护士僵尸礼包",lock:false,isask:false,picName:"jstx_hushijiangshi_sl",type:"c"});
			this.addItem( {itemName:"酒鬼僵尸礼包",lock:false,isask:false,picName:"jstx_jiugui_sl",type:"c"});
			this.addItem( {itemName:"酒鬼僵尸礼包",lock:false,isask:false,picName:"jstx_jiugui_sl",type:"c"});
			this.addItem( {itemName:"护士僵尸礼包",lock:false,isask:false,picName:"jstx_hushijiangshi_sl",type:"a"});
			this.addItem( {itemName:"程序员僵尸礼包",lock:false,isask:false,picName:"jstx_chengxuyuan_sl",type:"a"});
			this.addItem( {itemName:"服务员僵尸礼包",lock:false,isask:false,picName:"jstx_fuwuyuan_sl",type:"b"});
			reshow();
			
			this.getChildByName("btnGive").addEventListener(MouseEvent.CLICK, btnClick);
		}
		
		public function btnClick(e:Event):void
		{
			if( ( typeNumA + typeNumB + typeNumC) >= this.maxNum)return;
			if( null		==	this.selectItem)return;
			switch(this.selectItem.type)
			{
				case "a":this.typeNumA++;break;
				case "b":this.typeNumB++;break;
				case "c":this.typeNumC++;break;
			}
			this.setabc(typeNumA,typeNumB,typeNumC);
		}
		
		public function getFilters():void
		{
			filtersMzlb2	=	(this.getChildByName("mzlb2") as Sprite).filters;
			filtersMzlbAsk2	=	(this.getChildByName("mzlbask2") as Sprite).filters;
			filtersMzlbAsk1	=	(this.getChildByName("mzlbask1") as Sprite).filters;
			filterslblock	=	(this.getChildByName("lblock") as Sprite).filters;
			filtersHotTxt	=	(this.getChildByName("hottxt") as  TextField).filters;
		}
		
		public function addItem(obj:Object):void
		{
			items.push(obj);
		}
		
		public function reshow():void
		{
			var i:uint;
			for( i=1; i<=13; i++)
			{	
				( this.getChildByName("item" + i) as GiveItem).clean(); 
			}
			
			
			var an:uint=1;
			var bn:uint=6;
			var cn:uint=11;
			var giveitem:GiveItem;

			for( i=0; i<items.length; i++)
			{
				var isShow:Boolean	=	false;
				switch( items[i].type){
					case "a":
						giveitem	=	this.getChildByName("item" + an) as GiveItem;
						an++;
						if( this.typeNumA < this.typeAry[0])isShow=true;
						break;
					case "b":
						giveitem	=	this.getChildByName("item" + bn) as GiveItem;
						bn++;
						if( this.typeNumB < this.typeAry[1])isShow=true;
						break;
					case "c":
						giveitem	=	this.getChildByName("item" + cn) as GiveItem;
						cn++;
						if( this.typeNumC < this.typeAry[2])isShow=true;
						break;
				}
				if( giveitem){
					giveitem.setData( items[i]);
					
					if(!isShow){
						giveitem.lock	=	true;
						giveitem.reshow();
					}
					giveitem.reshow();
				}
			}
			
		}
		
//		static public function get instance():FriendGive
//		{
//			if(null==_instance)_instance=new FriendGive;
//			return _instance;
//		}
		
		public var needGrade:uint;
		public function setItemsVisible():void
		{
			
		}
		
		public function setabc(a:uint,b:uint,c:uint):void
		{
			this.typeNumA	=	a;
			this.typeNumB	=	b;
			this.typeNumC	=	c;
			
			( this.getChildByName("txtHaveNum") as TextField).text	=	( this.maxNum	-	(this.typeNumA + this.typeNumB + this.typeNumC)).toString();
			this.reshow();
		}
		
	}
}